package com.cat.slidingWindow;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-number-of-vowels-in-a-substring-of-given-length/
 * @create 2025/8/15 08:54
 * @since JDK17
 */

public class Solution27 {
    boolean check(char a) {
        return a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u';
    }
    public int maxVowels(String s, int k) {
        int ans = 0, n = s.length(), cnt = 0;
        for(int l = 0, r = 0; r < n; r++) {
            cnt += check(s.charAt(r)) ? 1 : 0;  // 元音就加一
            if (r - l + 1 >= k) {   // 到了k个
                ans = Math.max(ans, cnt);
                cnt -= check(s.charAt(l++)) ? 1 : 0;
            }
        }
        return ans;
    }
}
